#include <stddef.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
/*
7-15 QQ帐户的申请与登陆

输入样例:
5
L 1234567890 myQQ@qq.com
N 1234567890 myQQ@qq.com
N 1234567890 myQQ@qq.com
L 1234567890 myQQ@qq
L 1234567890 myQQ@qq.com

输出样例:

ERROR: Not Exist
New: OK
ERROR: Exist
ERROR: Wrong PW
Login: OK

*/
struct Account{
    char qq[10];
    char pw[16];
    struct Account *next;
}Account;
typedef struct Account *AccList;

AccList Find(char *qq, AccList list){
    AccList p = list;
    while(p){
        if(strcmp(qq, p->qq) == 0){
            return p;
        }
        p = p->next;
    }
    return NULL;
}

void AddAcc(char *qq, char *pw, AccList *list){
    AccList node = (AccList)calloc(1, sizeof(struct Account));
    node->next = NULL;
    strcpy(node->qq, qq);
    strcpy(node->pw, pw);
    if(*list != NULL){
        node->next = *list;
    }
    *list = node;
}

bool CheckPw(char *in, char *save){
    int len = 16;
    if(strlen(in)!=strlen(save)){
        return false;
    }
    for(int i =0; i<len; i++){
        if(in[i] == '\0'){
            break;
        }
        if(in[i]!=save[i]){
            return false;
        }
    }
    return true;
}

int main(){
    int n;
    AccList acclist=NULL;
    scanf("%d", &n);
    char type;
    char qq[10];
    char pw[16];
    for(int i = 0; i < n; i++){
        scanf(" %c", &type);
        scanf(" %s", qq);
        scanf(" %s", pw);
        AccList res = NULL;
        if(type == 'L'){
            res = Find(qq, acclist);
            if(res == NULL){
                printf("ERROR: Not Exist\n");
            }else{
                if(CheckPw(pw, res->pw)){
                    printf("Login: OK\n");
                }else{
                    printf("ERROR: Wrong PW\n");
                }
                
            }
        }else if (type == 'N'){
            res = Find(qq, acclist);
            if(res){
                printf("ERROR: Exist\n");
            }else{
                AddAcc(qq, pw, &acclist);
                printf("New: OK\n");
            }
        }
    }
}